package com.sgcc.operate.controller;

import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.sgcc.common.security.service.TokenService;
import com.sgcc.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sgcc.common.log.annotation.Log;
import com.sgcc.common.log.enums.BusinessType;
import com.sgcc.common.security.annotation.PreAuthorize;
import com.sgcc.operate.domain.OContentStat;
import com.sgcc.operate.service.IOContentStatService;
import com.sgcc.common.core.web.controller.BaseController;
import com.sgcc.common.core.web.domain.AjaxResult;
import com.sgcc.common.core.utils.poi.ExcelUtil;
import com.sgcc.common.core.web.page.TableDataInfo;

/**
 * 内容效能评估Controller
 * 
 * @author sgcc
 * @date 2021-03-31
 */
@RestController
@RequestMapping("/contentstat")
public class OContentStatController extends BaseController
{
    @Autowired
    private IOContentStatService oContentStatService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询内容效能评估列表
     */
    //@PreAuthorize(hasPermi = "operate:contentstat:list")
    @GetMapping("/list")
    public TableDataInfo list(OContentStat oContentStat)
    {
        startPage();
        List<OContentStat> list = oContentStatService.selectOContentStatList(oContentStat);
        return getDataTable(list);
    }

    /**
     * 导出内容效能评估列表
     */
    //@PreAuthorize(hasPermi = "operate:contentstat:export")
    @Log(title = "内容效能评估", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OContentStat oContentStat) throws IOException
    {
        List<OContentStat> list = oContentStatService.selectOContentStatList(oContentStat);
        ExcelUtil<OContentStat> util = new ExcelUtil<OContentStat>(OContentStat.class);
        util.exportExcel(response, list, "contentstat");
    }

    /**
     * 获取内容效能评估详细信息
     */
    //@PreAuthorize(hasPermi = "operate:contentstat:query")
    @GetMapping(value = "/{statDate}")
    public AjaxResult getInfo(@PathVariable("statDate") String statDate)
    {
        return AjaxResult.success(oContentStatService.selectOContentStatById(statDate));
    }

    /**
     * 新增内容效能评估
     */
    //@PreAuthorize(hasPermi = "operate:contentstat:add")
    @Log(title = "内容效能评估", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OContentStat oContentStat)
    {
        return toAjax(oContentStatService.insertOContentStat(oContentStat));
    }

    /**
     * 修改内容效能评估
     */
    //@PreAuthorize(hasPermi = "operate:contentstat:edit")
    @Log(title = "内容效能评估", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OContentStat oContentStat)
    {
        return toAjax(oContentStatService.updateOContentStat(oContentStat));
    }

    /**
     * 删除内容效能评估
     */
    //@PreAuthorize(hasPermi = "operate:contentstat:remove")
    @Log(title = "内容效能评估", businessType = BusinessType.DELETE)
	@DeleteMapping("/{statDates}")
    public AjaxResult remove(@PathVariable String[] statDates)
    {
        return toAjax(oContentStatService.deleteOContentStatByIds(statDates));
    }

    /**
     * 阅读统计数
     * @return
     */
    @GetMapping(value = "readNum")
    public AjaxResult readNum(OContentStat contentStat) {
        LoginUser loginUser = tokenService.getLoginUser();
        contentStat.setUserDeptId(loginUser.getSysUser().getDeptId());
        HashMap<String, Object> map = oContentStatService.readNum(contentStat);
        return AjaxResult.success(map);
    }

    /**
     * 内容地区投放情况
     * @return
     */
    @GetMapping(value = "pubAreaNum")
    public AjaxResult pubAreaNum(OContentStat contentStat) {
        LoginUser loginUser = tokenService.getLoginUser();
        contentStat.setUserDeptId(loginUser.getSysUser().getDeptId());
        List<HashMap<String, Object>> map = oContentStatService.pubAreaNum(contentStat);
        return AjaxResult.success(map);
    }

    /**
     * 内容投放情况
     * @return
     */
    @GetMapping(value = "pubNum")
    public AjaxResult pubNum(OContentStat contentStat) {
        LoginUser loginUser = tokenService.getLoginUser();
        contentStat.setUserDeptId(loginUser.getSysUser().getDeptId());
        List<HashMap<String, Object>> map = oContentStatService.pubNum(contentStat);
        return AjaxResult.success(map);
    }

    /**
     * 阅读排行top10
     * @return
     */
    @GetMapping(value = "readTop")
    public AjaxResult readTop() {
        Map map = new HashMap();
        List<HashMap<String, Object>> mapm = oContentStatService.readTopm();
        List<HashMap<String, Object>> mapd = oContentStatService.readTopd();
        map.put("readTopm", mapm);//本月排行
        map.put("readTopd", mapd);//昨日排行
        return AjaxResult.success(map);
    }

    /**
     * 分享排行top10
     * @return
     */
    @GetMapping(value = "shareTop")
    public AjaxResult shareTop() {
        Map map = new HashMap();
        List<HashMap<String, Object>> mapm = oContentStatService.shareTopm();
        List<HashMap<String, Object>> mapd = oContentStatService.shareTopd();
        map.put("shareTopm", mapm);
        map.put("shareTopd", mapd);
        return AjaxResult.success(map);
    }
}
